package net.huashitong.service.money;

import net.huashitong.mapper.money.SsMoneyGoldRecordMapper;
import net.huashitong.ssydt.PaginationResult;
import net.huashitong.ssydt.money.entity.SsMoneyGoldRecord;
import net.huashitong.ssydt.money.entity.vo.GoldsRecordsMyInVO;
import net.huashitong.ssydt.money.entity.vo.SsMoneyGoldRecordQueryInVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

;

/**
 * @author huiyang.yu
 */
@Service
@Transactional
public class SsMoneyGoldRecordServiceImpl implements SsMoneyGoldRecordService {

    private SsMoneyGoldRecordMapper mapper;

    @Autowired
    public SsMoneyGoldRecordServiceImpl(SsMoneyGoldRecordMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public List<SsMoneyGoldRecord> queryIdDescByUserId(GoldsRecordsMyInVO goldsRecordsMyInVO) {
        return mapper.queryIdDescByUserId(goldsRecordsMyInVO);
    }

    @Override
    public void save(SsMoneyGoldRecord ssMoneyGoldRecord) {
        mapper.insert(ssMoneyGoldRecord);
    }

    @Override
    public PaginationResult<SsMoneyGoldRecord> paginationQuery(SsMoneyGoldRecordQueryInVO ssMoneyGoldRecordQueryInVO) {
        PaginationResult result = new PaginationResult();
        result.setPageNumber(ssMoneyGoldRecordQueryInVO.getPageNumber());
        result.setPageSize(ssMoneyGoldRecordQueryInVO.getPageSize());

        // 查询记录总数
        int total = mapper.queryCount(ssMoneyGoldRecordQueryInVO);
        result.setPageRecords(total);

        if (total == 0) {
            result.setList(new ArrayList());
        } else {
            // 查询当前页记录
            List<SsMoneyGoldRecord> list = mapper.query(ssMoneyGoldRecordQueryInVO);
            result.setList(list);
        }
        return result;
    }
}
